﻿namespace InvoiceInvoker.Logic
{
	public partial class RegisteredProduct
	{
		public Product ToProduct(decimal quantity, bool setId = false)
		{
			Product product = new Product();

			if (setId)
				product.Id = this.Id;

			product.Name = this.Name;
			product.Pkwiu = this.Pkwiu;
			product.Quantity = quantity;
			product.MeasureUnit = this.MeasureUnit;
			product.NetPrice = this.NetPrice;
			product.NetValue = decimal.Round((this.NetPrice * quantity).Value, 2);
			product.VatRate = this.VatRate;

			int vatPercentage = VatRatesProvider.GetVatPercentage(this.VatRate);
			product.VatValue = decimal.Round((product.NetValue * (vatPercentage * 0.01M)).Value, 2);
			product.GrossValue = product.NetValue + product.VatValue;

			return product;
		}
	}
}
